package define

import (
	"encoding/json"
	"strings"
)

const (
	AgentStateReady    = "Ready"
	AgentStateNotReady = "NotReady"
	AgentStateUnKnow   = "UnKnown"
)

type AgentInfo struct {
	Guid     string `json:"guid" yaml:"guid"`
	IP       string `json:"ip_address" yaml:"ip_address"`
	MAC      string `json:"mac_address" yaml:"mac_address"`
	CPUs     string `json:"cpu_cores" yaml:"cpu_cores"`
	MEM      string `json:"memory_bytes" yaml:"memory_bytes"`
	OS       string `json:"os" yaml:"os"`
	Arch     string `json:"arch" yaml:"arch"`
	Hostname string `json:"host_name" yaml:"host_name"`

	Status string `json:"status" yaml:"status"`
	Area   string `json:"area" yaml:"area"`

	// coded string, use the flow function to translate it
	Services string `json:"services" yaml:"services"`
	Tags     string `json:"tags" yaml:"tags"`
	//Instances string `json:"instances" yaml:"instances"`
}

const (
	SEP = `#`
)

// eg: prometheus,jaeger,
func EncodeService(service interface{}) string {
	return strings.Join(service.([]string), SEP)
}

func DecodeService(service string) interface{} {
	return strings.Split(service, SEP)
}

// eg: k1=v1,k2=v2
func EncodeTags(tags interface{}) string {
	jsonStr, err := json.Marshal(tags)
	if err != nil {
		return ""
	}

	return string(jsonStr)
}

func DecodeTags(tags string) interface{} {
	tagMap := make(map[string]string)
	err := json.Unmarshal([]byte(tags), &tagMap)
	if err != nil {
		return nil
	}
	return tagMap
}

// eg: ins1,ins2,ins3
func EncodeInstaces(instace interface{}) string {
	return ""
}

func DecodeInstaces(instace string) interface{} {
	return ""
}
